package com.rf.controller;

import com.rf.bean.Student;
import com.rf.mapper.StudentMapper;
import com.rf.page.PageBean;
import com.rf.service.StudentService;
import com.rf.vo.ResponseVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Description
 * @Author rf
 * @Date 2022/4/2
 */

@RestController
@RequestMapping("/stu")
public class StudentController {

    @Resource
    private StudentService studentService;

    @RequestMapping
    public ResponseVo getAll(PageBean<Student> pageBean){
        studentService.getByPage(pageBean);
        return ResponseVo.SUCCESS(pageBean);
    }

    @PutMapping
    public ResponseVo update(Student student){
        System.out.println(student);
        boolean rest = studentService.update(student);
        return rest ? ResponseVo.SUCCESS : ResponseVo.FAIL;
    }

    @DeleteMapping("/{id}")
    public ResponseVo del(@PathVariable Integer id){
        boolean rest = studentService.delete(id);
        return rest ? ResponseVo.SUCCESS : ResponseVo.FAIL;
    }

    @PostMapping
    public ResponseVo save(Student student){
        boolean rest = studentService.add(student);
        return rest ? ResponseVo.SUCCESS : ResponseVo.FAIL;
    }



}
